package com.first.group.oldhouse.service.impl;

import com.first.group.common.utils.R;
import com.first.group.oldhouse.service.OldHouseImgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.first.group.common.utils.PageUtils;
import com.first.group.common.utils.Query;

import com.first.group.oldhouse.dao.OldHouseDao;
import com.first.group.oldhouse.entity.OldHouseEntity;
import com.first.group.oldhouse.service.OldHouseService;


@Service("oldHouseService")
public class OldHouseServiceImpl extends ServiceImpl<OldHouseDao, OldHouseEntity> implements OldHouseService {


    @Autowired
    private OldHouseImgService oldHouseImgService;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<OldHouseEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("old_home_type",0);
        IPage<OldHouseEntity> page = this.page(
                new Query<OldHouseEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

    @Override
    public R saveOldHouse(OldHouseEntity oldHouse) {

        //添加二手房
        oldHouse.setOldHomeType(0);
        String oldFloor = "";
        oldFloor = oldHouse.getNowFloor()+"/"+oldHouse.getTotalFloor();
        oldHouse.setOldHouseFloorLevel(oldFloor);
        baseMapper.insert(oldHouse);
        //添加图片
        oldHouseImgService.saveImages(oldHouse.getOldHouseId(),oldHouse.getFileList());
        return R.ok();
    }

}